<?php

/**
 * WeEngine System
 *
 * (c) We7Team 2021 <https://www.w7.cc>
 *
 * This is not a free software
 * Using it under the license terms
 * visited https://www.w7.cc for more details
 */

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::prefix('user')->group(function () {
    Route::post('login', [\App\Http\Controllers\UserController::class, 'login']);
    Route::middleware('auth')->group(function () {
        Route::post('add', [\App\Http\Controllers\UserController::class, 'add']);
        Route::post('list', [\App\Http\Controllers\UserController::class, 'list']);
        Route::post('save', [\App\Http\Controllers\UserController::class, 'save']);
        Route::post('delete', [\App\Http\Controllers\UserController::class, 'delete']);
        Route::post('logout', [\App\Http\Controllers\UserController::class, 'logout']);
    });
});
Route::middleware('auth')->prefix('pay')->group(function () {
    Route::get('', function () {
        return view('pay');
    });
    Route::prefix('alipay')->group(function () {
        Route::get('pc', [\App\Http\Controllers\AlipayController::class, 'pc']);
        Route::get('wap', [\App\Http\Controllers\AlipayController::class, 'wap']);
        Route::post('refund', [\App\Http\Controllers\AlipayController::class, 'refund']);
    });
    Route::prefix('wechat')->group(function () {
        Route::post('pc', [\App\Http\Controllers\WechatController::class, 'pc']);
        Route::post('refund', [\App\Http\Controllers\WechatController::class, 'refund']);
    });
    Route::post('list', [\App\Http\Controllers\PayController::class, 'list']);
});

Route::get('/', function () {
    return view('login');
})->name('login');

Route::middleware('auth')->get('/user', function () {
    return view('user');
})->name('user');

Route::get('static/{path}', function ($path) {
    $file = dirname(__DIR__, 1) . '/public/' . $path;
    $mime = new \Symfony\Component\Mime\MimeTypes();
    $mimeType = $mime->getMimeTypes((new SplFileInfo($file))->getExtension())[0] ?? 'text/html';
    \Illuminate\Support\Facades\Response::make()->header('Content-Type', $mimeType)
        ->setContent(file_get_contents(dirname(__DIR__, 1) . '/public/' . $path))
        ->send();
})->where('path', '.*');
